package com.neuedu.web.servlet;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * @auth 金山老师
 * title:   书籍代码
 * creatime: 2022-10-19 14:08
 * 描述 :
 *
 * http://localhost:8080/web/api?name=abc&age=100
 */
@WebServlet(value = "/api")
public class ApiServlet  extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //获取参数的
        request.getParameter("");

        //获取多个同名参数
        request.getParameterValues("");

        //获取请求头
        String userAgent = request.getHeader("User-Agent");
        System.out.println("userAgent = " + userAgent);

        //请求参数    ？后的内容
        String queryString = request.getQueryString();
        System.out.println("queryString = " + queryString);

        //请求地址
        StringBuffer requestURL = request.getRequestURL();
        System.out.println("requestURL = " + requestURL);

        //请求的短地址
        String requestURI = request.getRequestURI();
        System.out.println("requestURI = " + requestURI);


        //上下文
        String contextPath = request.getContextPath();
        System.out.println("contextPath = " + contextPath);

        String method = request.getMethod();
        System.out.println("method = " + method);


        /**
         * 响应对象
         */
        response.setHeader("autologin","true");





    }
}
